<?php

interface DatabaseConnection
{
    /**
     * Perform a query on the database
     * @param string $sql
     * @return DatabaseResult
     */
    public function query($sql);
    
    /**
     * Prepare a query on the database
     * @param string $sql
     * @param string $types
     * @return DatabaseStatement
     */
    public function prepare($sql, $types = NULL);
    
    /**
     * Escapes data
     * in dependency of the config var magic_quotes_gpc
     * Recursive on arrays
     *
     * @param string|array $var
     * @return string|array $escaped
     */
    public function escape($sql);
    
    /**
     * Replace the placeholder for the table praefix
     * @param string $sql
     * @return string
     */
    public function replacePraefix($sql);
    
    /**
     * Gets the first affected records as an associative array
     * @param string $sql
     * @return array|false result array or failure
     */
    public function getOne($sql);
    
    /**
     * Perform a query and fetch all
     * @param string $sql
     * @return array|false result array or failure
     */
    public function getAll($sql);
    
    /**
     * Modify the index getAll() is using for return arrays
     * use an empty string to get numeric indexes
     * @param string $modifyTo
     */
    public function getAllIndex($modifyTo);
    
    /**
     * Get the querycount
     * @return integer
     */
    public function queryCount();
    
    /**
     * Perform a multiquery
     * @param string $sql
     * @return array
     */
    public function multiQuery($sql);
    /**
     * Perform multiple inserts
     *
     * @param string $table
     * #@ param string $types $types, 
     * @param array $values
     * @param boolean $escape
     * @return boolean $success
     */
    public function multiInsert($table, array $values, $escape = true);
    /**
     * Perform multiple updates
     *
     * @param string $table
     * @param array $update
     * @param string $additionalWhere
     * @param string $index
     * @param boolean $escape
     * @return boolean $success
     */
    public function multiUpdate($table, array $update, $additionalWhere = '', $index = 'id', $escape = true);
    
    /**
     * Perform an INSERT query
     *
     * @param string $table
     * @param array $i
     * @param boolean $escape
     * @return integer insert_id
     */
    public function sqlInsert($table, array $i, $escape = true);
    /**
     * Perform an UPDATE query
     *
     * @param string $table
     * @param array $update
     * @param string $where
     * @param boolean $escape
     * @return boolean $success
     */
    public function sqlUpdate($table, array $update, $where = '', $escape = true);
    /**
     * Perform a SELECT query
     *
     * @param string $table
     * @param string $where
     * @param boolean $all
     * @param string $select
     * @return array
     */
    public function sqlSelect($table, $where = '', $all = true, $select = '*');
    
    /**
     * Update the database by comparing two arrays with modified data
     * in addition, a check for write rights can be performed while comparing
     *  only rows with write rights true will get an update
     *
     * @param array $newest_array
     * @param array $older_array
     * @param string $sqltable
     * @param string $wherekey
     * @param array $write_rights
     * @param boolean $check_write_rights
     * @return integer count updated rows
     */
    public function actualizeArray(array $newest_array, array $older_array, $sqltable, $wherekey = 'id', array $write_rights = array(), $check_write_rights = false);
    
    /**
     * Close resource manually
     *
     */
    public function close();
   
}